#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<assert.h>
#include<cstring>
using namespace std;
//模板类
template <typename T> 
class stack 
{
public:
  //构造函数
  stack()
    :_p(nullptr)
    ,_top(0)
    ,_capacity(4)
  {}
  //析构函数
  ~stack()
  {
    delete[] _p;
    _p = nullptr;
    _top=_capacity=0;
  }
  void push(T x)
  {
    if(_p==nullptr)
    {
      _p=new T[_capacity];
    }
    if(_top == _capacity)
    {
      T* tem = new T[_capacity*2];
      memcpy(tem,_p,sizeof(T)*_capacity);
      delete[] _p;
      _p=tem;
      _capacity=2*_capacity;
    }
    _p[_top]=x;
    _top++;
  }
  bool empty()
  {
    return _top;
  }
  const T& Top()
  {
    return _p[_top-1];
  }
  void print()
  {
    int i=0;
    for(i=0;i<_top;i++)
      cout<<_p[i]<<"->";
    cout<<endl;
  }
private:
    T* _p;
    int _top;
    int _capacity;
};
